
/* GENERATED CODE:
 *  Any modifications you make are guaranteed
 *  to be deleted when this is regenerated.
 * Please edit "PROTOCOLS" inside this directory
 *
 * Names are all upper case because of "String" and "string."
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OWED.Network.Messages.General;
using OWED.Network.Messages;
using OWED.Network.Messages.Reply;


namespace OWED.Network.Messages.General
{
	public class Proposal: IProtocolItem 
	{
		ProposalID my_proposalid;
		DocName my_docname;
		Changes my_changes;
		Proposed my_proposed;
		Applied my_applied;
		bool my_isapplied;
		public Proposal (bool isapplied, ProposalID proposalid, DocName docname, Changes changes, Proposed proposed, Applied applied)
		{
			my_isapplied = isapplied;
			my_proposalid = proposalid;
			my_docname = docname;
			my_changes = changes;
			my_proposed = proposed;
			my_applied = applied;
		}
		public ProposalID ProposalID { get { return my_proposalid; } }
		public DocName DocName { get { return my_docname; } }
		public Changes Changes { get { return my_changes; } }
		public Proposed Proposed { get { return my_proposed; } }
		public Applied Applied { get { return my_applied; } }
		public bool isapplied { get { return my_isapplied; } }


		public static new Proposal FromXml(XmlDocument xml)
		{
			bool isapplied = bool.Parse(xml.SelectSingleNode("Proposal").Attributes.GetNamedItem("isapplied").Value);
			XmlDocument doc;
			if (xml.SelectSingleNode("Proposal/ProposalID") != null &&
					xml.SelectSingleNode("Proposal/DocName") != null &&
					xml.SelectSingleNode("Proposal/Changes") != null &&
					xml.SelectSingleNode("Proposal/Proposed") != null &&
					xml.SelectSingleNode("Proposal/Applied") != null) {
				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("Proposal/ProposalID"), true));
				ProposalID proposalid = ProposalID.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("Proposal/DocName"), true));
				DocName docname = DocName.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("Proposal/Changes"), true));
				Changes changes = Changes.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("Proposal/Proposed"), true));
				Proposed proposed = Proposed.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("Proposal/Applied"), true));
				Applied applied = Applied.FromXml(doc);

				return new Proposal(isapplied, proposalid, docname, changes, proposed, applied);
			}
			throw new ConnectionException("Bad document supposedly of type:Proposal");
		}


		public override XmlDocument ToXml()		{
			XmlDocument doc = new XmlDocument();

			doc.AppendChild(doc.CreateElement("Proposal"));
			XmlAttribute attr;
			attr = doc.CreateAttribute("isapplied");
			attr.Value = my_isapplied.ToString();
			doc.FirstChild.Attributes.Append(attr);


			if (my_proposalid != null) {
				XmlNode node;
				node = doc.ImportNode(my_proposalid.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_docname != null) {
				XmlNode node;
				node = doc.ImportNode(my_docname.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_changes != null) {
				XmlNode node;
				node = doc.ImportNode(my_changes.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_proposed != null) {
				XmlNode node;
				node = doc.ImportNode(my_proposed.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_applied != null) {
				XmlNode node;
				node = doc.ImportNode(my_applied.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			return doc;
		}
	}
}
